// 订阅的指标
import { IDashboard } from '@/pages/data';

export interface subscribeWidgetsItem {
  config: string;
  description: string;
  id: number;
  isSubscribe: boolean;
  name: string;
  position: string;
  projectId: number;
  publish: boolean;
  subscribeId: number;
  type: number;
  viewId: number;
}

// 移动模板配置
export interface GridLayoutsItem {
  x: number;
  y: number;
  w: number;
  h: number;
  i: string;
}

// 项目列表
export interface PanelsParentItem {
  projectId: number;
  projectName: string;
}

export interface H5WidgetsItem {
  id: number;
  projectId: string;
  shareToken: string;
  text: string;
}

// 看板列表
export interface PanelsItem extends PanelsParentItem {
  dashboardId: number;
  dashboardName: string;
  dashboardPortalId: number;
  dashboardPortalName: string;
  h5Widgets: Array<H5WidgetsItem>;
  shareToken: string;
}

export interface dashboardWidgetsItem {
  config: string;
  dashboardId: number;
  frequency: number;
  height: number;
  id: number;
  polling: boolean;
  widgetId: number;
  widgetName: string;
  width: number;
  x: number;
  y: number;
  viewId: number;
}

// 看板详情
export interface IDashboardItem {
  config: string;
  dashboardPortalId: number;
  id: number;
  index: number;
  name: string;
  parentId: number;
  type: number;
  groups: Array<dashboardGroupsItem>
  widgets: Array<dashboardWidgetsItem>;
}

export interface dashboardGroupsItem {
  WidgetsArr?: Array<dashboardWidgetsItem>;
  dashboardId?: number;
  groupName: string;
  id: number;
  isDelete?: boolean;
  widgets: string;
}


// 指标列表
export interface WidgetsItem {
  config: IChartConfig;
  id: number;
  model: any;
  projectId: number;
  shareToken: string;
  text: string;
  widgetId: number;
  widgetName: string;
}

export interface IWidget {
  config: string
  createTime: string
  description: string
  id: number
  isSubscribe: boolean
  name: string
  projectId: number
  publish: boolean
  type: number
  updateTime: string
  viewId: number
  dashboard:IDashboard
}

// 指标渲染出图表的配置
export interface IChartConfig {
  selectedChart: number;
  cols: Array<ICol>;
  metrics: Array<IMetric>;
  chartStyles: {
    bar: {
      barChart: boolean;
      stack: {
        on: boolean;
        percentage: boolean;
      };
    };
    table: ITableConfig;
    label: {
      showLabel: boolean;
    };
    legend: {
      showLegend: boolean;
    };
  };
  color: {
    items: Array<{
      name: string;
      config: {
        actOn: string;
        values: any;
      };
    }>;
  };
  filters: Array<any>;
  orders: Array<any>;
  drills: Array<IDrill>;
  customFilters: Array<ICustomFilter>;
  model: any;
  cache: boolean
  expired: number
}

// 图表的数据过滤，筛选等配置
export interface IChartDataFilterConfigs {
  groups: Array<string>;
  aggregators: Array<IAggregator>;
  filters: Array<any>;
  orders: Array<any>;
  pageNo: number;
  pageSize: number;
  nativeQuery: boolean;
  cache: boolean;
  expired: number;
  flush: boolean;
}

// 指标查看详情数据集合
export interface IndexDetailItem {
  configs: IChartConfig;
  dataRecord: DataRecord;
  filterConfigs: IChartDataFilterConfigs;
  subscribe: boolean;
  widget: dashboardViewsItem;
}

// 查看的指标详情
export interface dashboardViewsItem {
  config: string;
  description: string;
  id: number;
  model: string;
  name: string;
  projectId: number;
  sourceId: number;
  sql: string;
  variable: string;
  widgetId: number;
  widgetName: string;
}

export interface IChartFormat {
  formatType: string;
  percentage: {
    decimalPlaces: number;
  };
  numeric: {
    decimalPlaces: number;
    unit: string;
    useThousandSeparator: boolean;
  };
  currency: {
    decimalPlaces: number;
    unit: string;
    prefix: string;
    suffix: string;
    useThousandSeparator: boolean;
  };
}

export interface IMetric {
  name: string;
  agg: string;
  format: IChartFormat;
  field: {
    alias: string;
  };
  calculate: any;
  totalType?: string
}

export interface IDrill {
  name: string;
  visualType: string;
  type: string;
  config: boolean;
  field: {
    alias: string;
    useExpression: boolean;
    desc: string;
  };
  format: {
    formatType: string;
  };
}

export interface ICustomFilter {
  config: boolean;
  field: {
    useExpression: boolean;
    alias: string;
    desc: string;
  };
  format: {
    formatType: string;
  };
  from: string;
  name: string;
  type: string;
  visualType: string;
}

export interface ITableConfig {
  headerConfig: ITableHeaderConfig[];
  columnsConfig: ITableColumnConfig[];
  leftFixedColumns: string[];
  rightFixedColumns: string[];
  headerFixed: boolean;
  bordered: boolean;
  size: 'default' | 'middle' | 'small';
  autoMergeCell: boolean;
  withPaging: boolean;
  pageSize: string;
  withNoAggregators: boolean;
}

export interface ITableCellStyle {
  fontFamily: string;
  fontWeight: string;
  fontColor: string;
  fontStyle: 'normal' | 'oblique';
  justifyContent: 'flex-start' | 'center' | 'flex-end';
}

export interface ITableHeaderConfig {
  key: string;
  headerName: string;
  alias: string;
  visualType: string;
  isGroup: boolean;
  style: ITableCellStyle;
  children: ITableHeaderConfig[];
}

export interface ITableColumnConfig {
  columnName: string;
  alias: string;
  sort?: boolean;
  visualType: string;
  style: ITableCellStyle;
}

export interface ICol {
  config: boolean;
  name: string;
  sort: {
    sortType: string;
    custom: {
      sortList: Array<any>;
    };
  };
  field: { alias: string };
  format: IChartFormat;
  type: string;
  visualType: string;
  dateType?: string;
}

export interface IAggregator {
  column: string;
  func: string;
  calculate: string;
}

export interface IModel {
  column: string;
  visualType: string;
  modelType?: string;
}

export interface IFilter {
  name: string;
  /**
   * 做函数封装的字段（regexp_extract(departmentname, '[^-|_]+$',0)）
   */
  column?: string;
  operator: string;
  type: string;
  sqlType: string;
  value: any;
  action: string;
  label?: string;
  visualType?: string;
  /**
   * 是否是可筛选的输入值
   */
  isCustomFilter?: boolean;
  /**
   * 单个层级路径，是否按下一级下钻
   */
  isLevelFilter?: boolean;
  /**
   * 所选的值是或的关系，不是and的关系，所以要加上isOr=true，给程序去做合并(为了能够叉掉筛选)
   */
  isOr?: boolean;
}

export interface DataRecordColumns {
  name: string;
  type: string;
}

export interface DataRecord {
  resultList: any;
  totalDatas?: any
  columns: Array<DataRecordColumns>;
}

export interface ICostCenter {
  departmentCode: string;
  departmentId: string;
  departmentLongName: string;
  departmentName: string;
  superiorDepartmentId: string;
}

export interface IDepartment {
  id: string;
  serialNo: string;
  name: string;
  displayName: string;
  parentSerialNo: string;
  enabled: number;
}

export interface ISubject {
  subjectNumber: string;
  subjectCode: string;
  subjectName: string;
  subjectLongName: string;
  subjectId: string;
  superiorSubjectsId: string;
  iD: number;
}
